#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int main(int argc, char const *argv[])
{
    set<pair<int, int> > temps;
    set<pair<int, int> >::iterator p;
    long long sum;
    int n, i, temp;

    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> temp;
        temps.insert(make_pair(temp, i));
    }

    sum = 0;
    for (i = 0; i < n - 1; i++)
    {
        p = temps.begin();
        temp = (*p).first;
        p++;
        temp += (*p).first;
        sum += temp;
        temps.erase(temps.begin());
        temps.erase(temps.begin());
        temps.insert(make_pair(temp, n + i));
    }   

    cout << sum;

    return 0;
}
